package com.cn.data.multipledata.api.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cn.data.commont.entity.AppUser;
import com.cn.data.multipledata.api.mapper.AppUserMapper;
import com.cn.data.multipledata.api.service.AppUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DS("one")
public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> implements AppUserService {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Override
    public Integer get(Integer userId) {
//        String sql="select * from app_user where userid=?";
//        AppUser appUser = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<AppUser>(AppUser.class),userId);
        String sql="select count(*) from app_user where userid=?";
        Integer count = jdbcTemplate.queryForObject(sql, Integer.class,userId);

        return count;
    }

    @Override
    public List<AppUser> getList() {
        String sql="select userid,coin,create_time from app_user";
        List<AppUser> appUser = jdbcTemplate.query(sql, new BeanPropertyRowMapper<AppUser>(AppUser.class));
        return appUser;
    }
}
